﻿using GC_FFW.ForecastWriterClient.Abstractions;
using GC_FFW.ForecastWriterClient.Abstractions.Interfaces.Factories.ViewModel;
using GC_FFW.ForecastWriterClient.ViewModels.Parameters;
using System;
using System.Windows;

namespace GC_FFW.ForecastWriterClient.WindowAdapters
{
	public class MatchDataEditorWindowAdapter : WindowBaseAdapter
	{
		#region Variables

		private readonly IMatchDataEditorViewModelFactory _factory;

		private readonly MatchDataEditorViewModelParameters _parameters;

		#endregion

		#region Constructors

		public MatchDataEditorWindowAdapter(Window wpfWindow, IMatchDataEditorViewModelFactory factory, MatchDataEditorViewModelParameters parameters)
			: base(wpfWindow)
		{
			if (factory == null)
				throw new ArgumentNullException(string.Format("VMFactory"));
			_factory = factory;

			if (factory == null)
				throw new ArgumentNullException(string.Format("parameters"));
			_parameters = parameters;
		}

		#endregion

		#region Override Methods

		protected override void EnsureInitialized()
		{
			if (IsWpfWindowInitialized) return;

			var viewModel = _factory.Create(_parameters);
			WpfWindow.DataContext = viewModel;

			IsWpfWindowInitialized = true;
		}

		#endregion
	}
}
